package main

import (
	"database/sql"
	"fmt"
	"github.com/gin-gonic/gin"
	_ "github.com/go-sql-driver/mysql"
	"net/http"
)

func main() {
	c := gin.Default()

	// 引入静态文件：html+css等
	c.Static("../html/static", "../html/static")
	c.LoadHTMLGlob("../html/page/*")
	c.GET("/login", func(ctx *gin.Context) {
		ctx.HTML(http.StatusOK, "index.html", gin.H{
			"msg": "登录界面",
		})
	})

	c.POST("user/login", func(ctx *gin.Context) {
		username := ctx.PostForm("username")
		password := ctx.PostForm("password")
		ctx.JSON(200, gin.H{
			"username": username,
			"password": password,
		})
	})

	c.Run(":8842")
}

// 定义连接数据库的函数：
func Connect_to_db() {
	db, err := sql.Open("mysql", "root:root@tcp(127.0.0.1:3306)/tjs_purchase")
	if err != nil {
		fmt.Println("连接出错：", err)
		return
	}
	defer db.Close()

}
